* Figure 3
use "./data/publications.dta", clear
createvarspub
gen hiqual=(abs=="4" | abs=="4*" | cnrs=="1" | cnrs=="1e" | cnrs=="1g")
gen other=1-hiqual
gen tnat_hi=tnational*hiqual
gen tport_hi=tportpub*hiqual
gen tpfa_hi=tpfaonly*hiqual
gen tnat_ot=tnational*other
gen tport_ot=tportpub*other
gen tpfa_ot=tpfaonly*other
bys article_id: keep if _n==1
collapse (sum) hiqual other *_hi *_ot, by(year)
keep if year>1999
gen shtotal=hiqual/(hiqual+other)*100
label var shtotal "All articles"
gen shnat=tnat_hi/(tnat_hi+tnat_ot)*100
label var shnat "Portuguese institutions"
gen shtpor=tport_hi/(tport_hi+tport_ot)*100
label var shtpor "Core institutions"
gen shpfa=tpfa_hi/(tpfa_hi+tpfa_ot)*100
label var shpfa "Foreign institutions"
* Share of "quality" over the years
tsset year
twoway ///
(tsline shtotal, lwidth(medium) lpattern(dash)) /// 
(tsline shnat, lwidth(medium) lpattern(shortdash_dot_dot)) /// 
(tsline shtpor, lwidth(medium)) ///
(tsline shpfa, lwidth(medium) lpattern(dash_dot_dot)), /// 
ytitle(Share of quality articles) graphregion(fcolor(white)) ///
legend(region(color(white))) scheme(sj)
graph export ./figures/fig3.pdf, replace

